﻿using CommunityToolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows;

namespace AppTemplate.UI.Controls
{
    public delegate void CloseTabHandler(ClosableTabItem tab);

    public class ClosableTabItem : TabItem
    {

        public RelayCommand CloseTabCommand { get; private set; }
        public ClosableTabItem()
        {
            CloseTabCommand = new RelayCommand(Close);
        }

        public static readonly DependencyProperty ClosableProperty = DependencyProperty.Register(nameof(Closable), typeof(bool), typeof(ClosableTabItem), new PropertyMetadata(false));

        public bool Closable
        {
            get
            {
                return (bool)GetValue(ClosableProperty);
            }
            set
            {
                SetValue(ClosableProperty, value);
            }
        }


        public event CloseTabHandler CloseTabHandler;

        public void Close()
        {
            this.CloseTabHandler?.Invoke(this);
        }


    }
}
